

package com.woniuxy.listener;

import com.rabbitmq.client.Channel;
import com.woniuxy.entity.Mail;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: 马宇航
 * @Description: TODO
 * @DateTime: 22/10/19/0019 16:50
 * @Component: 成都蜗牛学苑
 **/
@Component
public class CunsumerListener1 {
    @RabbitListener(queues = {"ProConQueue"})
    public void messageReceive(Mail mail, Channel channel, Message message) throws IOException {
        //设置限流
        channel.basicQos(1);
        //获取消息的tagid
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        //业务处理没异常则 确认该条消息
        channel.basicAck(deliveryTag,false);
        System.out.println("第一个消费者收到消息："+mail);
    }
}